package cn.lemon;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

import java.util.Set;

/**
 * @program: JedisDemo
 * @Date: 2019/1/7 22:08
 * @Author: Mr.huang
 * @Description:
 */
public class JedisDemo {

    public static void main(String[] args) {
        //连接redis
        Jedis jedis=new Jedis("129.204.167.189",6379,5000);
        //1.存字符串类型
        String set = jedis.set("key", "value4");
        //获取字符串类型的值
        String key = jedis.get("key");
        //2.存set类型的
        jedis.sadd("myset","value1","value2");
        //检查一个元素是否在集合中
        Boolean sismember = jedis.sismember("myset", "value11");
        System.out.println(sismember);
        //3.存取List类型
        jedis.rpush("List","list1","list2","list3");
        jedis.lpush("List","value00");
        //获取指定索引的元素
        String lindex0 = jedis.lindex("List", 0);
        System.out.println(lindex0);
        String lpop = jedis.lpop("List");
        String lindex01 = jedis.lindex("List", 0);
        System.out.println(lpop);
        //4.存取hash类型
        jedis.hset("hash","key1","value1");
        //获取hash的值
        String hget = jedis.hget("hash", "key1");
        System.out.println(hget);

        jedis.hincrBy("hash","key2",3);
        String hget2 = jedis.hget("hash", "key2");
        System.out.println(hget2);
//        System.out.println(key);

        Set<String> keys = jedis.keys("*");
        Transaction multi = jedis.multi();
        long l = System.currentTimeMillis();
        for (String s : keys) {
            System.out.println(s);
            multi.del(s);
        }
        multi.exec();
        long l1 = System.currentTimeMillis();
        System.out.println(l1-l);


    }



}
